import React from 'react';
import PropTypes from 'prop-types';//react 16.X这样用，改动太大，升级困难
import { DaysOfMonth } from '../const';

class Day extends React.Component {
    constructor(props) {
        super(props);
    }
    state = {

    }

    initState(year, month) {
        const now = new Date();
        const hour = now.getHours();
        let second = now.getSeconds();
        let minute = now.getMinutes();
        let milliseconds = now.getMilliseconds();

        if (minute < 10) {
            minute = '0' + minute;
        }
        if (second < 10) {
            second = '0' + second;
        }
        if (milliseconds < 10) {
            milliseconds = '00' + milliseconds;
        } else if (milliseconds < 100) {
            milliseconds = '0' + milliseconds;
        }

        this.setState({
            hour, minute, second, milliseconds
        })
    }

    componentWillMount() {
        this.initState();
        setInterval(() => { this.initState() }, 50)
    }

    getNow = () => {
        const state = this.state;
        return `${state.hour}:${state.minute}:${state.second}:${state.milliseconds}`
    }

    render() {

        return (<span>{this.getNow()}</span>);
    }
}

export default Day;
